import { Component, OnInit, Input } from '@angular/core';
import { VideoImgPopupComponent } from '../video-img-popup/video-img-popup.component';
import { ModalController } from "@ionic/angular";
import { ImgSlidePage } from '../slides-imgage/img-slide.page';
import { PageModalService } from 'src/app/shared/service/page-modal-service';
@Component({
  selector: 'app-service-case-list',
  templateUrl: './service-case-list.component.html',
  styleUrls: ['./service-case-list.component.scss'],
})
export class ServiceCaseListComponent implements OnInit {
  @Input() tagData: any;
  constructor(
    public modalController: ModalController,
    public pageModalService: PageModalService
  ) { }

  ngOnInit() {

  }
  async popup(url) {
    const data = [];
    if (url.videoUrl) {
      // tslint:disable-next-line: no-string-literal
      data['videoUrl'] = url.videoUrl.split(',');
    }
    if (url.imgUrl) {
      // tslint:disable-next-line: no-string-literal
      data['imgUrl'] = url.imgUrl.split(',');
    }
    if (data !== []) {
      const modal = await this.modalController.create({
        component: VideoImgPopupComponent ,
        componentProps: { tagData: data}
      });
      return await modal.present();
    }
  }

  async openImage(images) {
    if (images.imgUrl) {
      const urlArray = [];
      images.imgUrl.split(',').forEach(element => {
        urlArray.push(element);
      });
      const value = { img: urlArray, index: 0 };
      const modal = await this.modalController.create({
        component: ImgSlidePage,
        componentProps: { value: JSON.stringify(value) }
      });
      return await modal.present();
    }
  }

  openPage(link) {
    if (link) {
      this.pageModalService.openPage(link);
    }
  }
}
